#define _CRT_SECURE_NO_WARNINGS
#include"team.h"

tream* initial(queue** qu)
{
	tream* tre = (tream*)malloc(sizeof(tream));
	tre->capa = tre->top = 0;
	tre->tr = NULL;
	*qu = (queue*)malloc(sizeof(queue));
	(*qu)->front = (*qu)->tail = tre->top;
	return tre;
}

tream* creatcapa(tream* tre)
{
	if (tre->capa == tre->top)
	{
		int newcapa = tre->capa == 0 ? 4 : tre->capa * 2;
		tydata* tmp = (tydata*)realloc(tre->tr, newcapa * sizeof(tydata));
		if (tmp == NULL)
		{
			perror("error");
			return NULL;
		}
		tre->tr = tmp;
		tre->capa = newcapa;
	}
	return tre;
}

void destory(queue** qu,tream* tre)
{

}

void pushque(queue** qu,tream* tre, tydata x)
{
	assert(*qu);
	creatcapa(tre);
	tre->tr[tre->top] = x;
	tre->top++;
	(*qu)->tail = tre->top;
}

void popque(queue** qu,tream* tre)
{
	assert(*qu);
	assert(!judgeempty(*qu));
	for (int i = 0; i <tre->top; i++)
	{
		tre->tr[i] = tre->tr[i + 1];
	}
	tre->top--;
	(*qu)->tail = tre->top;
}

bool judgeempty(queue* qu)
{
	assert(qu);
	return qu->front == qu->tail;
	
}

tydata gettail(queue* qu,tream* tre)
{
	assert(qu);
	assert(!judgeempty(qu));
	return tre->tr[qu->tail - 1];
}

tydata getfront(queue* qu, tream* tre)
{
	assert(qu);
	assert(!judgeempty(qu));
	return tre->tr[qu->front];
}

tydata sizeofque(queue* qu)
{
	assert(qu);
	assert(!judgeempty(qu));
	return qu->tail - 1;
}